package cn.lnpu.freemarker.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Controller
public class FreemarkerController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/banner")
    public String banner(Map<String, Object> map){
        //                http://localhost:31001/cms/config/model/5a791725dd573c3574ee333f
        String dataUrl = "http://localhost:31001/cms/config/model/5a791725dd573c3574ee333f";
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(dataUrl, Map.class);
        Map body = forEntity.getBody();
        map.putAll(body);
        //返回模板文件名称

        return "index_banner";
    }


    @GetMapping("/course")
    public String course(Map<String, Object> map){
        String dataUrl = "http://localhost:31200/course/courseview/4028e581617f945f01617f9dabc40000";
        ResponseEntity<Map> forEntity = restTemplate.getForEntity(dataUrl, Map.class);
        Map body = forEntity.getBody();
        map.putAll(body);
        //返回模板文件名称

        return "course";
    }
}